﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.com.SistemaChamados.Controller.Common;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model.Common;

public partial class Pages_PersonMain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void deleteUser(int id)
    {
        User user = new User();
        UserController Controller = new UserController();
        user.Id = id;
        try
        {
            if (Controller.DeleteUser(user) == EnumGenericState.GENERIC_STATE_SUCCESS)
            {
                Response.Write(@"<script language='javascript'>alert('Pessoa excluida com Sucesso!');</script>");
            }
            else
            {
                Response.Write(@"<script language='javascript'>alert('Ocorreu um erro durante a exclusão, por favor tente novamente!');</script>");
            }
        }
        catch (Exception ex)
        {
            Response.Write(@"<script language='javascript'>alert('Ocorreu um erro na exclusão: <br>" + ex.Message +
                               ".');</script>");
            user = null;
        }
        finally
        {
            Response.Redirect("UserMain.aspx");
        }
    }
    protected void gdvUser_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        switch (e.CommandName)
        {
            case "Exclude":
                deleteUser(id);
                break;

            case "Update":
                Session["UserIdToUpdate"] = id;
                Response.Redirect("UserUpdate.aspx");
                break;
        }
    }
}